package com.imut.oa.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.imut.oa.pojo.dto.AttendancePageQueryDTO;
import com.imut.oa.pojo.dto.AttendanceRemarkDTO;
import com.imut.oa.pojo.dto.EmployeeAttendanceDTO;
import com.imut.oa.pojo.dto.WorkTimeConfigDTO;
import com.imut.oa.pojo.entity.Attendance;
import com.imut.oa.pojo.entity.Departments;
import com.imut.oa.pojo.vo.AttendanceRecordVO;
import com.imut.oa.pojo.vo.AttendanceVO;
import com.imut.oa.pojo.vo.LeaveVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;
import org.springframework.data.repository.query.Param;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface AttendanceMapper extends BaseMapper<Attendance> {
    Page<AttendanceVO> selectAttendancePage(
            Page<AttendanceVO> page,
            @Param("dto") AttendancePageQueryDTO attendancePageQueryDTO
    );
    @Update("update attendance set remark = #{remark} where id = #{id}")
    void updateRemark(AttendanceRemarkDTO attendanceRemarkDTO);
    @Insert("insert into attendance(employeeId,latitude,longitude,attendanceType,clockTime,status) values(#{employeeId},#{latitude},#{longitude},#{attendanceType},#{clockTime},#{status})")
    void attendance(EmployeeAttendanceDTO employeeAttendanceDTO);

    List<AttendanceRecordVO> findByEmployeeAndDateRange(
            @Param("employeeId") Long employeeId,
            @Param("startDate") LocalDateTime startDate,
            @Param("endDate") LocalDateTime endDate
    );

    WorkTimeConfigDTO getWorkTimeConfig();
    @Update("UPDATE attendance_config SET workTime = #{workTime}, offTime = #{offTime} WHERE id = 1")
    int updateWorkTimeConfig(WorkTimeConfigDTO workTimeConfigDTO);

    List<AttendanceRecordVO> getAttendanceRecords(@Param("employeeId") Long employeeId, @Param("offset") int offset, @Param("pageSize") int pageSize);


    List<Map<String, Object>> getAttendanceStats();
}
